home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Sample Code / AppsToGo / Kibitz / PPCBrowserOverride.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-24  |  6.7 KB  |  232 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        ppcbrowseroverride.c
  5. ** Written by:  C.K. Haun
  6. **
  7. ** Copyright © 1992 Apple Computer, Inc.
  8. ** All rights reserved. */
  9.  
  10.  
  11.  
  12. /*****************************************************************************/
  13.  
  14.  
  15.  
  16. #include "Kibitz.h"                /* Get the Kibitz includes/typedefs, etc.    */
  17. #include "KibitzCommon.h"        /* Get the stuff in common with rez.        */
  18. #include "Kibitz.protos"        /* Get the prototypes for Kibitz.            */
  19.  
  20. #ifndef __CONTROLS__
  21. #include <Controls.h>
  22. #endif
  23.  
  24. #ifndef __OSEVENTS__
  25. #include <OSEvents.h>
  26. #endif
  27.  
  28. #ifndef __TRAPS__
  29. #include <Traps.h>
  30. #endif
  31.  
  32.  
  33.  
  34. /*****************************************************************************/
  35.  
  36.  
  37.  
  38. /* Thanks to C.K. for his Hack-To-Go service here in DTS.  Just leave a message,
  39. ** and the hack will show up via QuickMail really soon.  This is really interesting,
  40. ** since I've seen him type.  I don't know how he gets them done so fast.
  41. ** My only figuring is that he doesn't waste too much time with the space or tab keys
  42. ** on his keyboard.  (I added the spaces and tabs.) */
  43.  
  44. /* Theory of hack:
  45. ** Lots of zones (which describes Apple) is a real pain to browse looking for a game
  46. ** of chess.  This hack allows a really slimy way of coercing PPCBrowser to scan the
  47. ** zones until it finds a zone that has a machine running Kibitz.  Since we figure
  48. ** that this need doesn't apply to many companies (how many companies have hundreds
  49. ** of zones?), there really isn't much need to spend too much time polishing this
  50. ** “feature”.
  51. **
  52. ** Since it is a really slimy hack, it was implemented into Kibitz as a hiddel feature.
  53. ** If you hold down the shift key when you do the menu command to connect to another
  54. ** player, then you have this auto-scan-of-zones feature active.  If the feature is
  55. ** active, then if you are displaying a zone that has no machine running Kibitz, after
  56. ** a maximum of 10 seconds, the patch posts a down-arrow.  The down arrow moves the
  57. ** zone list to the next available zone, assuming that the zone list is the active
  58. ** list.
  59. **
  60. ** Of course, if the zone list isn't the active zone, this feature isn't too useful.
  61. ** This is why it is a hack.  It does the job, if you know what you are doing.
  62. **
  63. ** It actually works reasonably well, as it beats the heck of choosing on the next
  64. ** zone by hand to see if anybody's running Kibitz in that zone.
  65. */
  66.  
  67.  
  68.  
  69. typedef struct myParamBlock {
  70.     short                activeFlag;
  71.     short                dialogUp;
  72.     short                scrollActive;
  73.     long                tickCounter;
  74.     UniversalProcPtr    oldGND;
  75.     UniversalProcPtr    oldMD;
  76.     UniversalProcPtr    oldDD;
  77.     long                oldFilter;
  78. } myParamBlock;
  79. myParamBlock OurParamBlock;
  80.  
  81. /* this define contains the ASCII and the keycode, in case anyone cares */
  82. /* This is, by the way, for a US keyboard in US script.  Your script may */
  83. /* vary, please check your owners manual */
  84.  
  85. #define kDownArrowKey 0x27D1F
  86. #define kFiveSeconds 300
  87.  
  88. extern void        GNDPatch(void);  /* the actual paramter passing doesn't matter here */
  89. extern void        MDPatch(void);
  90. extern void        DDPatch(void);
  91.  
  92. void            TogglePPCPatches(Boolean on);
  93. Boolean            CheckMachineList(void);
  94. void            DoModalFilter(void);
  95. ControlHandle    FindSB(WindowPtr theWindow);
  96.  
  97.  
  98.  
  99. /*****************************************************************************/
  100.  
  101.  
  102.  
  103. void    TogglePPCPatches(Boolean on) {
  104. #ifndef __MWERKS__
  105. #pragma unused (on)
  106. #endif
  107.  
  108. #ifndef powerc
  109.  
  110.     if (on) {        /* turn everything on */
  111.         OurParamBlock.activeFlag   = true;
  112.         OurParamBlock.dialogUp     = false;
  113.         OurParamBlock.scrollActive = false;
  114.         OurParamBlock.tickCounter  = 0;
  115.         OurParamBlock.oldGND       = NGetTrapAddress(_GetNewDialog,ToolTrap);
  116.         OurParamBlock.oldMD        = NGetTrapAddress(_ModalDialog,ToolTrap);
  117.         OurParamBlock.oldDD        = NGetTrapAddress(_DisposDialog,ToolTrap);
  118.  
  119.         /* and set them to what we want please */
  120.  
  121.         NSetTrapAddress((UniversalProcPtr)GNDPatch,_GetNewDialog,ToolTrap);
  122.         NSetTrapAddress((UniversalProcPtr)MDPatch,_ModalDialog,ToolTrap);
  123.         NSetTrapAddress((UniversalProcPtr)DDPatch,_DisposDialog,ToolTrap);
  124.     }
  125.     else {        /* turning off.  Kill ebbybiddy */
  126.         OurParamBlock.activeFlag   = false;
  127.         OurParamBlock.dialogUp     = false;
  128.         OurParamBlock.scrollActive = false;
  129.         OurParamBlock.tickCounter  = 0;
  130.  
  131.         /* revert the routines */
  132.  
  133.         NSetTrapAddress(OurParamBlock.oldGND,_GetNewDialog,ToolTrap);
  134.         NSetTrapAddress(OurParamBlock.oldMD,_ModalDialog,ToolTrap);
  135.         NSetTrapAddress(OurParamBlock.oldDD,_DisposDialog,ToolTrap);
  136.     }
  137. #endif
  138. }
  139.  
  140.  
  141.  
  142. /*****************************************************************************/
  143.  
  144.  
  145.  
  146. Boolean    CheckMachineList(void) {
  147.     short            v1, v2;
  148.     WindowPtr        theWind    = FrontWindow();
  149.     ControlHandle    theControl = ((WindowPeek)theWind)->controlList;
  150.     Rect            minRect    = {16000, 16000, 16000, 16000};
  151.     ControlHandle    minCtl     = nil;
  152.  
  153.     /* walk through the controls in the Front Window and find the scrollbar for the */
  154.     /* machine list.  If there are no machines listed, then we're happening. */
  155.     /* NOTE!!!! Avert young children's eyes at this point, please!  */
  156.     /* I'm being cheap and sleazy here, and using information about the */
  157.     /* PPC browser dialog (that you can see in MacsBug) itself to do this fast.*/
  158.  
  159.     while(theControl) {
  160.         v1 = (*theControl)->contrlRect.top + (*theControl)->contrlRect.left;
  161.         v2 = minRect.top + minRect.left;
  162.         if (v1 < v2) {
  163.             minRect = (*theControl)->contrlRect;
  164.             minCtl  = theControl;
  165.         }
  166.         theControl = (*theControl)->nextControl;
  167.     }
  168.  
  169.     if (minCtl)
  170.         if ((*minCtl)->contrlMax == -6)
  171.             return(true);
  172.  
  173.      return(false);
  174. }
  175.  
  176.  
  177.  
  178. /*****************************************************************************/
  179.  
  180.  
  181.  
  182. /* here's the workhorse for us */
  183. /* we make the following assumptions */
  184. /* well, only one really....    */
  185. /* the FrontWindow IS the PPC browser! */
  186. /* if this isn't true, then things are too weird for words */
  187.  
  188. void    DoModalFilter(void) {
  189.     if(TickCount() > OurParamBlock.tickCounter) {
  190.         OurParamBlock.tickCounter = TickCount() + kFiveSeconds;
  191.         if(CheckMachineList()) {
  192.             PostEvent(keyDown,kDownArrowKey);
  193.             PostEvent(keyUp,kDownArrowKey);
  194.         }
  195.     }
  196. }
  197.  
  198.  
  199.  
  200. /*****************************************************************************/
  201.  
  202.  
  203.  
  204. ControlHandle    FindSB(WindowPtr theWindow) {
  205.     Ptr                sBarProc, otherProc;
  206.     ControlHandle    theControls, fakeScroll;
  207.     WindowPeek        theWind = (WindowPeek)theWindow;
  208.     Rect            theRect = {0, 0, 9, 9};
  209.  
  210.     fakeScroll = NewControl((WindowPtr)theWind, &theRect, "\p", false, 0, 0, 10, 16, 0);
  211.     sBarProc   = *((*fakeScroll)->contrlDefProc);
  212.     StripAddress(&sBarProc);
  213.     DisposeControl(fakeScroll);
  214.  
  215.     theControls = theWind->controlList;
  216.     while (theControls) {
  217.         /* don't test against my sample */
  218.         if (theControls != fakeScroll) {
  219.             otherProc = *((*theControls)->contrlDefProc);
  220.             StripAddress(&otherProc);
  221.             if (otherProc == sBarProc)
  222.                 return(theControls);
  223.         }
  224.     }
  225.     theControls = (*theControls)->nextControl;
  226.  
  227.     return(nil);
  228. }
  229.  
  230.  
  231.  
  232.